import re

html = """
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document
    </title>
</head>
<body>
    <h1>正则测试1
    </h1>
    <h1>正则测试2
    </h1>
    <ul>
        <li><a href="https://www.baidu.com/news/1">连接1</a></li>
        <li><a href="https://www.baidu.com/news/2">连接2</a></li>
        <li><a href="https://www.baidu.com/news/3">连接3</a></li>
        <li><a href="https://www.baidu.com/news/4">连接4</a></li>
        <li><a href="https://www.baidu.com/news/5">连接5</a></li>
    </ul>
</body>
</html>
"""

# result = re.search(r'<title>(.*?)</title>',html,re.S)
# if result:
#     print(result.group(1).strip())
# else:
#     print("匹配失败")
#
#
#
# result = re.search(r'<h1>(.*?)</h1>',html,re.S)
# if result:
#     print(result.group(1).strip())
# else:
#     print("匹配失败")


# result = re.findall(r'<h1>(.*?)</h1>',html,re.DOTALL)
# for h1 in result:
#     print(h1.strip())




items = re.findall(r'<li><a href="(.*?)">(.*?)</a></li>',html)
for item in items:
    print(f"链接：{item[0]}  名字：{item[1]}")